//
//  StrategyCell.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/12/27.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class StrategyCell: UITableViewCell {
    
    var model : NewsModel! {
        didSet{
           updateData()
        }
    }
    
    fileprivate let newsImageView = UIImageView() //图片
    fileprivate let titleLabel = UILabel() //标题
    fileprivate let timeLabel = UILabel() //时间

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.contentView.backgroundColor = UIColor.white
        
        newsImageView.layer.cornerRadius = RATIO_H(maxNum: 10)
        newsImageView.layer.masksToBounds = true
        self.contentView.addSubview(newsImageView)
        
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        titleLabel.numberOfLines = 2
        self.contentView.addSubview(titleLabel)
        timeLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        timeLabel.textColor = UIColor.gray
        self.contentView.addSubview(timeLabel)
        newsImageView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 8))
            make.centerY.equalToSuperview()
            make.width.equalTo(RATIO(maxNum: 110))
            make.height.equalTo(RATIO_H(maxNum: 70))
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(newsImageView)
            make.right.equalToSuperview().offset(RATIO(maxNum: -8))
            make.left.equalTo(newsImageView.snp.right).offset(RATIO(maxNum: 8))
            make.height.greaterThanOrEqualTo(10)
        }
        timeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel)
            make.right.equalTo(titleLabel)
            make.bottom.equalTo(newsImageView)
            make.height.greaterThanOrEqualTo(10)
        }
    }
    
    //MARK: 刷新数据
    fileprivate func updateData() {
        
        newsImageView.setUrlImage(with: kmHttps + (model.image ?? ""), placeholder: UIImage.imageWithName("loading"))
        titleLabel.text = model.title
        timeLabel.text = model.time
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
